package elements
{
	import UIFree.controls.uif_hscrollArea;
	import UIFree.uif_component;
	
	import editor.pi_source;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	public class pi_photoList extends uif_hscrollArea {
		private var _selectIndex: int;
		 
		public function pi_photoList(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}
		
		
		public function loadPreviews(previewList: Array): void {
			var inner: Rectangle = _scroll.getInner();
			this.assignList(previewList, inner.height + 5, function(scroll: uif_component, rect: Rectangle, i:int): void {
				rect.inflate(-2, -2);
				var item: pi_source = new pi_source(scroll, rect.x, rect.y, rect.width, rect.height, 'hlist_item');
				item.loadSource(previewList[i]);
				item.addEventListener(MouseEvent.CLICK, function(e: MouseEvent): void {
					_selectIndex = i;
					dispatchEvent(new Event(Event.SELECT));
				});
			});
		}
		
		public function get selectIndex(): int {
			return _selectIndex;
		}
	}
}